<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "award_list".
 *
 * @property int $id
 * @property string $name 标题
 * @property string|null $desc 说明
 * @property string $create_time
 * @property string $update_time
 * @property int $count
 * @property float $balance
 * @property float $score
 * @property int $status
 */
class AwardList extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'award_list';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['desc'], 'string'],
            [['create_time', 'update_time'], 'safe'],
            [['count'], 'integer'],
            [['balance', 'score'], 'number'],
            [['name'], 'string', 'max' => 255],

            [['status'], 'safe']
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'desc' => 'Desc',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
            'count' => 'Count',
            'balance' => 'Balance',
            'score' => 'Score',
        ];
    }

    public function beforeSave($insert)
    {
        if (parent::beforeSave($insert)) {
            $time = date('Y-m-d H:i:s');
            $this->update_time = $time;
            if ($insert) {
                $this->create_time = $time;
            }
            return true;
        }
        return false;
    }
}
